<?php
/**
 * 检验签名中间件
 */

namespace App\middleware;

use App\model\Ban;
use app\model\User;
use app\service\GameService;
use support\Common;
use support\ErrorCode;
use support\Log;
use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;

class CheckBan implements MiddlewareInterface
{
    //时间范围
    const TIME_RANGE = 3600;

    public function process(Request $request, callable $handler): Response
    {
        // 请求继续向洋葱芯穿越
        $params = $request->postData;

        // 请求继续向洋葱芯穿越
        $is_ban = false;
        if (isset($params['uuid'])) {
            $is_ban = User::query()->where('uuid', $params['uuid'])->value('is_ban');
        }
        if ($is_ban) {
            return outJson(1, '已被封禁，详情请联系客服');
        }

        //判断是否封禁ip
        $is_ex = Ban::query()->Where('ip', $request->getRealIp())->exists();
        if ($is_ex) {
            return outJson(1, '已被封禁，详情请联系客服');
        }
        return $handler($request);
    }


}